home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / asmutil / xlt86.zip / XLT86.ASM < prev    next >
Assembly Source File  |  1985-08-15  |  49KB  |  3,181 lines

  1. ;*******************************************************
  2.     page 60,132
  3. ;
  4. ;            XLT86
  5. ;
  6. ; Translates Intel 8080 assembly language source code
  7. ;  to Intel 8086 assembly language source code.
  8. ;
  9. ; 11/11/84 Frank J. Zerilli
  10. ;
  11. ; 8086 version, 11/20/84
  12. ;
  13. ;
  14. ; MS-DOS version 12/20/84
  15. ;  by Craig Derouen
  16.  
  17. VERS    EQU    110
  18. ;
  19. ;*******************************************************
  20. ;
  21. ;      XLT86 processes lines with the exclamation point
  22. ; statement separator correctly.  It strips trailing
  23. ; blanks or tabs from lines.  It replaces initial
  24. ; asterisks in lines with semicolons.  It provides
  25. ; several options to format the output file for best
  26. ; appearance.
  27. ;      This program gives the choice of converting the
  28. ; case of instructions to upper or lower case or of
  29. ; trying to preserve the case of instructions.
  30. ;      An activity dot is printed on the console for
  31. ; every 100 lines of input processed.
  32. ;
  33. ; Command line:
  34. ;
  35. ;     XLT86 [d:]srcfile[.typ] [d:destfile.typ]
  36. ;
  37. ;      All parameters in brackets are optional, and, if
  38. ; omitted, the default values are:
  39. ;
  40. ;  Source file-type      -- ASM
  41. ;  Destination file-type -- A86
  42. ;  Destination file-name -- same as the source file-name
  43. ;  Drive                 -- current drive
  44. ;
  45. ; FLAG LOCATIONS:
  46. ;
  47. ; 103H -- Change to non-zero value to suppress
  48. ;      translation of several non-standard opcodes:
  49. ;      REQ, RNE, RLT, RGE, CEQ, CNE, CLT, CGE
  50. ;      JEQ, JNE, JLT, JGE,
  51. ;      ENT, NAM, RAM, ROG, IFC, ICL, LST, MAC
  52. ;
  53. ; 104H -- If non-zero (default) XLT86 converts lines
  54. ;      with multiple statements separated by DR's EP
  55. ;      separator into separate lines.
  56. ;      Change to zero for output on a single line
  57. ;      with the translated statements separated by
  58. ;      EP.
  59. ;
  60. ; 107H--  If zero (default) XLT86 translates
  61. ;
  62. ;        PUSH PSW    POP PSW
  63. ;
  64. ;      to
  65. ;
  66. ;        LAHF        POP AX
  67. ;        PUSH AX        SAHF
  68. ;
  69. ;      Otherwise, the translation is
  70. ;
  71. ;        LAHF        POP AX
  72. ;        XCHG AH,AL    XCHG AH,AL
  73. ;        PUSH AX        SAHF
  74. ;        XCHG AH,AL
  75. ;
  76. ; 108H-- If zero (default) XLT86 translates
  77. ;
  78. ;        INX rp        DCX rp
  79. ;
  80. ;     to
  81. ;
  82. ;        INC rp'        DEC rp'
  83. ;
  84. ;     Otherwise, the translation is
  85. ;
  86. ;        PUSHF        PUSHF
  87. ;        INC rp'        DEC rp'
  88. ;        POPF        POPF
  89. ;
  90. ; 109H-- If zero (default) XLT86 translates
  91. ;
  92. ;        DAD rp
  93. ;
  94. ;     to
  95. ;
  96. ;        ADD BX,rp'
  97. ;
  98. ;     Otherwise, the translation is
  99. ;
  100. ;        PUSHF
  101. ;        ADD BX,rp'
  102. ;        POPF
  103. ;
  104.  
  105. N00    EQU    0
  106. N01    EQU    1
  107. ;
  108. N07    EQU    7
  109. N09    EQU    9        ;tab every 8th col.
  110. NF8    EQU    0F8H        ;mod 8
  111. ;
  112. LBUFLN    EQU    80        ;line buffer length
  113. OPBFLN    EQU    5        ;opcode buffer length
  114. MEMSIZ    EQU    4        ;memory available in Kb
  115. IBNUM    EQU    4*MEMSIZ
  116. OBNUM    EQU    4*MEMSIZ
  117. RECLEN    EQU    128        ;
  118. STCKLN    EQU    128        ;stack size
  119. IBFLEN    EQU    IBNUM*RECLEN
  120. OBFLEN    EQU    OBNUM*RECLEN
  121. ;
  122. CTRLC    EQU    3
  123. EOT    EQU    4
  124. BEL    EQU    7
  125. HT    EQU    9
  126. LF    EQU    0AH
  127. CR    EQU    0DH
  128. ESC    EQU    1BH
  129. QUOTE    EQU    27H
  130. ;
  131.  
  132. code    segment byte
  133.  
  134.     assume cs:code,ds:code
  135.  
  136.     ORG    005CH
  137. DFCB1    DB    16 DUP(?)
  138. DFCB2    DB    16 DUP(?)
  139. ;
  140. FNLEN    EQU    8
  141. EOS    EQU    EOT        ; replacement for exclamation pt
  142. EOF    EQU    1AH
  143. NFF    EQU    0FFH        ;disk error return
  144. ;
  145. ;    BDOS FUNCTIONS
  146. ;
  147. nABT    EQU    0
  148. nCIN    EQU    1
  149. nCOUT    EQU    2
  150. nCDAV    EQU    0BH
  151. nOPEN    EQU    0FH
  152. nCLOSE    EQU    10H
  153. nDEL    EQU    13H
  154. nRDNR    EQU    14H
  155. nWRNR    EQU    15H
  156. nCREAT    EQU    16H
  157. nCDISK    EQU    19H
  158. nDMA    EQU    1AH
  159. ;
  160. ;
  161. ;
  162.     ORG    100H
  163. ;
  164. HERE_FIRST:
  165.  
  166.     JMP    START
  167. ;
  168. ; OPTION FLAGS
  169. ;
  170. PSEFLG    DB    0        ;(103H) 0 to translate non-
  171.                 ;  standard opcodes
  172. MLTLFL    DB    0FFH        ;(104H) 0 to put input line with
  173.                 ;  exc. pt. to output on one line
  174. TCASFL    DB    0        ;(105H) 0 to preserve case
  175.                 ;
  176. LCASFL    DB    0        ;(106H) 0 for upper case if
  177.                 ;  TCASFL not zero
  178. PSWFL    DB    0        ;(107H) non-zero to preserve 8080
  179.                 ;  order of PSW registers on stack
  180. INXFL    DB    0        ;(108H) non-zero to preserve flags
  181.                 ;  with INX and DCX translations
  182. DADFL    DB    0        ;(109H) non-zero to preserve flags
  183.                 ;  with DAD translation
  184.                 
  185. ;
  186. ; BDOS Functions
  187. ;
  188. BDOS:
  189.     INT    21H
  190.     RET
  191.  
  192. ;
  193. ; RETURN TO MSDOS
  194. ;
  195. ABORT:    MOV    AH,4ch
  196.     INT    21h
  197.  
  198. ;
  199. ;  HELP MESSAGE
  200. ;
  201. HMSG1:
  202.  
  203.  DB CR,LF
  204.  DB LF
  205.  DB 'XLT86 translates Intel 8080 assembly language source',CR,LF
  206.  DB 'code into Intel 8086 assembly language source code.',CR,LF
  207.  DB LF
  208.  DB 'It is invoked by a command of the form:',CR,LF
  209.  DB LF
  210.  DB '    XLT86 [d:]srcfile[.typ] [d:destfile.typ]',CR,LF
  211.  DB LF
  212.  DB 'The brackets denote optional parameters and the ',CR,LF
  213.  DB 'default values are:',CR,LF
  214.  DB LF
  215.  DB '    Source file-type      --  ASM',CR,LF
  216.  DB '    Destination file-type --  A86',CR,LF
  217.  DB '    Destination file-name --  same as source file-name',CR,LF
  218.  DB '    Drive                 --  current drive',CR,LF
  219.  DB CR,LF
  220.  DB 'Press any key to continue - ',0
  221.  
  222. HMSG2:
  223.  
  224.  DB CR,LF
  225.  DB LF
  226.  DB 'Examples:',CR,LF
  227.  DB LF
  228.  DB 'XLT86 PRGM1               --translates PRGM1.ASM to PRGM1.A86',CR,LF
  229.  DB 'XLT86 PRGM1 PRGM2         --translates PRGM1.ASM to PRGM2.A86',CR,LF
  230.  DB 'XLT86 PRGM1.TXT PRGM2.MAC --translates PRGM1.TXT to PRGM2.MAC',CR,LF
  231.  DB LF
  232.  DB 'XLT86 also has the following features:',CR,LF
  233.  DB LF
  234.  DB 'Case will be preserved as well as possible -- if an opcode has',CR,LF
  235.  DB 'a lower case character, the translated opcode will be in lower',CR,LF
  236.  DB 'case.',CR,LF
  237.  DB LF
  238.  DB 'All asterisks at the beginning of lines will be replaced with',CR,LF
  239.  DB 'semicolons.',CR,LF
  240.  DB LF
  241.  DB 'A dot is printed on the console for every 100 lines of input ',CR,LF
  242.  DB 'processed.',CR,LF
  243.  DB LF
  244.  DB 0
  245. ;
  246. ;=============================================================================
  247. ;
  248. ; Program begins here
  249. ;
  250. START:
  251.     MOV    AX,SS
  252.     MOV    SSBDOS,AX
  253.     MOV    SPBDOS,SP
  254.  
  255.     MOV    AX,CS
  256.     MOV    SS,AX
  257.     MOV    SP,OFFSET STACK
  258.  
  259.     MOV    AL,DFCB1+1    ; check for a file name
  260.     CMP    AL,' '        ; print help if no name
  261.     JNZ    BEGIN        ; no help requested
  262.     MOV    DX,OFFSET SIGNON
  263.     CALL    PRTLIN
  264.     MOV    DX,OFFSET HMSG1    ; print help message
  265.     CALL    PRTLIN
  266.     MOV    AH,nCIN        ; wait for any character
  267.     CALL    BDOS
  268.     MOV    DX,OFFSET HMSG2    ; print rest of help
  269.     CALL    PRTLIN
  270.  
  271.     MOV    AX,SSBDOS
  272.     MOV    SS,AX        ; retrieve system stack
  273.     MOV    SP,SPBDOS    ;  pointer and pop
  274.     MOV    al,2        ; put in an error code
  275.     MOV    AH,4CH
  276.     INT    21H        ; Return to DOS
  277.  
  278. BEGIN:    CALL    HELLO        ;signon, open in & out files
  279. NXTLIN:    CALL    GETLIN        ;get line from input file to buf
  280.     CALL    PROCLIN        ; process line
  281.     JMP    NXTLIN
  282. ;
  283. ;
  284. ;
  285.  
  286. ;*******************************************************
  287. ;
  288. ;    Print signon, open input
  289. ;    and output files.
  290. ;
  291. HELLO:    MOV    DX,OFFSET SIGNON
  292.     CALL    PRTLIN
  293. HELLO0:    MOV    AL,'D'        ; translate DB & EQU (for
  294.     MOV    OPTBDB,AL    ;  uniform formatting)
  295.     MOV    MLTSPC,HT    ; for opcodes xltd to mlt stmts
  296.     MOV    AL,HT        ; HT after opcode
  297.     MOV    BX,OFFSET PUTHT+1
  298.     MOV    [BX],AL
  299.     MOV    AL,41        ; tab comments to col 33
  300.     MOV    BX,OFFSET PUTND5+1
  301.     MOV    [BX],AL
  302.     MOV    AL,3CH        ; CMP instruction
  303.     MOV    BX,OFFSET EXCLAM
  304.     MOV    [BX],AL
  305.     XOR    AL,AL
  306.     MOV    TCASFL,AL    ; don't convert case
  307.     MOV    LCASFL,AL    ; lower case flag
  308.     MOV    SEPMSG,OFFSET NEWLSP
  309.  
  310.     MOV    AL,PSEFLG    ; translate non-standard
  311.     OR    AL,AL        ;  opcodes ?
  312.     JZ    LBL1
  313.      CALL NXPSD
  314. LBL1:
  315.  
  316.     MOV    DX,OFFSET DBMSG
  317.     CALL    PRTLIN        ;
  318.     CALL    CHKYES        ; xlat DB & EQU ?
  319.     CMP    AL,ESC
  320.     JNZ    LBL2
  321.      JMP HELLO0
  322. LBL2:
  323.     CMP    AL,CTRLC
  324.     JNZ    LBL3
  325.      JMP ABORT
  326. LBL3:
  327.     CMP    AL,'Y'
  328.     JZ    LBL4
  329.      CALL NXDBEQ
  330. LBL4:
  331.  
  332.     MOV    AL,MLTLFL    ; force space after opcode
  333.     OR    AL,AL        ;  if MLTLFL not set
  334.     JNZ    LBL5
  335.      JMP HELLO2
  336. LBL5:
  337.     MOV    DX,OFFSET SPCMSG
  338.     CALL    PRTLIN        ; use space after
  339.     CALL    CHKYES        ; opcode ?
  340.     CMP    AL,ESC
  341.     JNZ    LBL6
  342.      JMP HELLO0
  343. LBL6:
  344.     CMP    AL,CTRLC
  345.     JNZ    LBL7
  346.      JMP ABORT
  347. LBL7:
  348.     CMP    AL,'Y'
  349. HELLO2:    JNZ    LBL8
  350.      CALL SETSPC
  351. LBL8:
  352.  
  353.     MOV    DX,OFFSET COLMSG
  354.     CALL    PRTLIN        ;
  355.     CALL    CHKYES        ; start comment
  356.     CMP    AL,ESC
  357.     JNZ    LBL9
  358.      JMP HELLO0
  359. LBL9:
  360.     CMP    AL,CTRLC
  361.     JNZ    LBL10
  362.      JMP ABORT
  363. LBL10:
  364.     CMP    AL,'Y'
  365.     JNZ    LBL11
  366.      CALL SETCOL ; in column 25 ?
  367. LBL11:
  368.  
  369.     MOV    DX,OFFSET EXCMSG
  370.     CALL    PRTLIN        ; Ignore exclamation point
  371.     CALL    CHKYES        ;  separator ?
  372.     CMP    AL,ESC
  373.     JNZ    LBL12
  374.      JMP HELLO0
  375. LBL12:
  376.     CMP    AL,CTRLC
  377.     JNZ    LBL13
  378.      JMP ABORT
  379. LBL13:
  380.     CMP    AL,'Y'
  381.     JNZ    LBL14
  382.      CALL SETNEX
  383. LBL14:
  384.  
  385.     MOV    DX,OFFSET MLTMSG
  386.     CALL    PRTLIN        ; multiple statements
  387.     CALL    CHKYES        ; on one line ?
  388.     CMP    AL,ESC
  389.     JNZ    LBL15
  390.      JMP HELLO0
  391. LBL15:
  392.     CMP    AL,CTRLC
  393.     JNZ    LBL16
  394.      JMP ABORT
  395. LBL16:
  396.     CMP    AL,'Y'
  397.     JNZ    LBL17
  398.      CALL SETMLT
  399. LBL17:
  400.  
  401.